package com.dyzx.hbb.modules.wms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dyzx.hbb.common.config.MyLambdaQueryWrapper;
import com.dyzx.hbb.modules.wms.entity.WmsProduct;
import com.dyzx.hbb.modules.wms.service.WmsProductService;
import com.dyzx.hbb.modules.wms.mapper.WmsProductMapper;
import com.dyzx.hbb.security.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【wms_product(产品主数据表，包含产品名称、规格、条码等)】的数据库操作Service实现
* @createDate 2025-09-20 10:40:36
*/
@Service
public class WmsProductServiceImpl extends ServiceImpl<WmsProductMapper, WmsProduct>
    implements WmsProductService{

    @Override
    public WmsProduct findById(Long productId) {
        Long organId = SecurityContextHolder.getOrganId();
        MyLambdaQueryWrapper<WmsProduct> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.eq(WmsProduct::getId, productId);
        queryWrapper.select(WmsProduct::getId)
                .select(WmsProduct::getName)
                .select(WmsProduct::getInternalCode)
                .select(WmsProduct::getStatus)
                .select(WmsProduct::getCreateDate)
                .select(WmsProduct::getUpdateDate)
                .select(WmsProduct::getCategoryId)
                .select(WmsProduct::getSupplierId)
                .select(WmsProduct::getUnitOfMeasure)
                .select(WmsProduct::getWeight)
                .select(WmsProduct::getDimensions)
                .select(WmsProduct::getImageUrl)
                .select(WmsProduct::getIsActive)
                .select(WmsProduct::getQualityTraceFlag)
                .select(WmsProduct::getStandardCompliance)
                .select("IFNULL((SELECT  SUM(amt) FROM `wms_product_task` where product_id=wms_product.id and  `organ_id` = " + organId + "),0)").as("amt")
                .select(WmsProduct::getGrossweight)
                .select(WmsProduct::getNetweight)
                .select(WmsProduct::getWidth)
                .select(WmsProduct::getHeight)
                .select(WmsProduct::getDepth)
                .select(WmsProduct::getOrigincountry)
                .select(WmsProduct::getOriginplace)
                .select(WmsProduct::getAssemblycountry)
                .select(WmsProduct::getCompany)
                .select(WmsProduct::getEname)
                .select(WmsProduct::getUnspsc)
                .select(WmsProduct::getBrand)
                .select(WmsProduct::getNetcontent);


        return baseMapper.selectOne(queryWrapper);
    }
}




